<html>
<head>
<meta charset="UTF-8">
<title>批次配置</title>
	<link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css" />
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css" />
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
<style>
    .selected{background-color: #cde4fc;}
	.tba,.tba th,.tba td{text-align:center;border: 1px solid #bcc1c2;border-collapse:collapse;}
	.tba th{font-weight:normal;font-size:15px;background-color: #5173a0;color:white}
	.tba th,.tba td{height:30px;min-width:30px;overflow:hidden;white-space:nowrap;}
	.tba td{font-size:14px;cursor: hand;}
	.tba td:hover{background-color: #ddecfc;}
	.tba{min-width:850px;margin: 0 auto;border:none;}
	.tbHr{border-bottom:none;position:relative;width:100%;}
</style>
<script type="text/javascript">

	var currentSelected="";
	var subsCode=$.getUrlParam("subsCode");

	$(function(){
		document.getElementById("batchId").innerHTML = $.getUrlParam("batchId");
		document.getElementById("batchName").innerHTML = $.getUrlParam("batchName");
		document.getElementById("launchType").innerHTML = getNameByDic($.getUrlParam("launchType")).toString();
		document.getElementById("equallyTaskAmount").innerHTML = $.getUrlParam("equallyTaskAmount");
		inite();
	});

	function getNameByDic(enname) {
		for(var i in this.BAT_LAUNCH_TYPE){
			if(this.BAT_LAUNCH_TYPE[i].enname==enname){
				return this.BAT_LAUNCH_TYPE[i].cnname;
			}
		}
	}

	function inite(){
		$.restfulPostForm('../../api/bat/batch/stage/configs',{batchId: $.getUrlParam('batchId')},function(data){
			if(data.rows.length>0){
				$("#taskPhase tbody").append(createBatchNode(data.rows));
			} else{
				$.messager.alert('提示','当前批次阶段配置为空！','info');
			}
		});
	}

	function createBatchNode(phases) {
		$("#taskPhase tbody").empty();
		var html="";
		for(var i in phases){
			var phase=phases[i];
			var tasks=getStageTask(phase.batchId,phase.stageId);
			var l=Math.ceil(tasks.length/7)>0?Math.ceil(tasks.length/7):1;
			for(var j=0;j<l;j++){
				if(j==0){
					html+="<tr><td id='"+phase.stageId+"'>"+phase.stageName+"</td>";
				}else{
					html+="<tr><td></td>";
				}
				for(var k=0;k<7;k++){
					if(tasks!=null&&(7*j+k)<tasks.length){
						html+="<td id='"+tasks[7*j+k].taskId+"'>"+tasks[7*j+k].taskName+"</td>";
					}else{
						html+="<td></td>";
					}
				}
				html+="</tr>";
			}
			html+="</tr>";
		}
		return html;
	}

	function getStageTask(batchId,stageId){
		var result;
		$.restfulPostForm('../../api/bat/task/unit/configs',{batchId: batchId, stageId: stageId},function(data){
			result=data.rows;
		});
		return result;
	}

	function addTask(){
		var node=$("#taskPhase td.selected")[0];
		if (node && currentSelected=="phase") {
			JLEUtil.createModalWin('新增', 'BatTaskUnitConfigAdd.html?batchId='+$.getUrlParam('batchId')+"&stageId="+node.id);
		}else{
			$.messager.alert('提示','请选择一条阶段记录！','info');
		}
	}

	function updateTask(){
		var node=$("#taskPhase td.selected")[0];
		if (node && currentSelected=="task"){
			JLEUtil.createModalWin('修改', 'BatTaskUnitConfigUpdate.html?' + 'taskId=' + node.id);
		} else {
			$.messager.alert('提示','请选择一条任务记录！','info');
		}
	}

	function deleteTask(){
		var node=$("#taskPhase td.selected")[0];
		if (node && currentSelected=="task") {
			$.messager.confirm('删除提示', '你确定要删除这条记录?', function(r){
				if (r){
					var jsonData = JSON.parse('{'+'"taskId":"' + node.id + '"'+'}');
					$.restfulDelete('../../api/bat/task/unit/config', jsonData, function(data) {
						$.messager.alert('提示','记录删除成功!','info');
						inite();
					});
				}
			});
		} else {
			$.messager.alert('提示','请选择一条任务记录！','info');
		}
	}

	function viewTask(){
		var node=$("#taskPhase td.selected")[0];
		if (node && currentSelected=="task"){
			JLEUtil.createModalWin('修改', 'BatTaskUnitConfigView.html?' + 'taskId=' + node.id);
		} else {
			$.messager.alert('提示','请选择一条任务记录！','info');
		}
	}

	function addPhase(){
		JLEUtil.createModalWin('新增', 'BatBatchStageConfigAdd.html?batchId='+$.getUrlParam('batchId'));
	}

	function updatePhase(){
		var row=$("#taskPhase td.selected")[0];
		if (row && currentSelected=="phase"){
			JLEUtil.createModalWin('修改', 'BatBatchStageConfigUpdate.html?' + 'stageId=' + row.id + '&batchId=' + $.getUrlParam('batchId'));
		} else {
			$.messager.alert('提示','请选择一条阶段记录！','info');
		}
	}

	function deletePhase(){
		var row=$("#taskPhase td.selected")[0];
		if (row && currentSelected=="phase") {
			$.messager.confirm('删除提示', '你确定要删除这条记录?', function(r){
				if (r){
					var jsonData = JSON.parse('{'+'"stageId":"' + row.id + '"' + ','+'"batchId":"' + $.getUrlParam('batchId') + '"'+'}');
					$.restfulDelete('../../api/bat/batch/stage/config', jsonData, function(data) {
						$.messager.alert('提示','记录删除成功!','info');
						inite();
					});
				}
			});
		} else {
			$.messager.alert('提示','请选择一条阶段记录！','info');
		}
	}

	function viewPhase(){
		var row=$("#taskPhase td.selected")[0];
		if (row && currentSelected=="phase") {
			JLEUtil.createModalWin('详情','BatBatchStageConfigView.html?' + '&stageId=' + row.id + '&batchId=' + $.getUrlParam('batchId'));
		} else {
			$.messager.alert('提示','请选择一条阶段记录！','info');
		}
	}

	 $(document).click(function(e){
	 	$("#taskPhase td").removeClass("selected");
	 	if(e.target.localName=="td" && e.target.id!=""){
			if($("#"+e.target.id).is(':first-child')){
				currentSelected="phase";
			}else{
				currentSelected="task";
			}
			$("#"+e.target.id).addClass("selected");
		}
	 })

	function reloadList(){
		inite();
		JLEUtil.closewin();
	}

</script>
</head>
<body class="easyui-layout" style="padding: 10px">
	<div data-options="region:'north',split:true" style="width: 100%; height: 100%;">
		<div style="margin-bottom: 2px;padding:4px;width:100%;background-color: #ebecee">
			<a href="#" class="easyui-menubutton" data-options="menu:'#phaseAct'" style="background-color:#e7eaed">&nbsp;&nbsp;阶段管理</a>
			<a href="#" class="easyui-menubutton" data-options="menu:'#taskAct'" style="background-color:#e7eaed;">&nbsp;&nbsp;任务管理</a>
			<span>|</span>
			<span style="color: #40a0ff"> 阶段可直接新增 </span>
			<span> | </span>
			<span style="color: #40a0ff"> 任务新增需选中阶段 </span>
			<span> | </span>
			<span style="color: #40a0ff">  其它操作需选择相应元素 </span>
			<span> | </span>
			<span style="color: #40a0ff">  空白格不可选中 </span>
			<span> | </span>
		</div>
		<form style="margin-top:20px;">
				<table id="taskPhase" class="tba">
					<thead>
					<tr style="background-color: white">
						<th colspan='8' style="padding:0px;font-size:14px;height:45px;text-align:left;border: none;background-color: white;color:#3c3c3c;">
							<div style="position: relative;" >
								<div style="display: inline-block;margin-right: 15px;"><span>批次名称：</span><span id="batchName"></span></div>
								<div style="display: inline-block;margin-right: 15px;"><span>批次标识：</span><span id="batchId"></span></div>
								<div style="display: inline-block;margin-right: 15px;"><span>发起方式：</span><span id="launchType"></span></div>
								<div style="display: inline-block;margin-right: 15px;"><span>任务并发数：</span><span id="equallyTaskAmount"></span></div>
							</div>
							<hr class="tbHr">
							<div id="phaseAct" style="width: 100px;">
								<div onclick="javascript:addPhase()">新增阶段</div>
								<div onclick="javascript:deletePhase()">删除阶段</div>
								<div onclick="javascript:updatePhase()">修改阶段</div>
								<div onclick="javascript:viewPhase()">查看阶段</div>
							</div>
							<div id="taskAct" style="width: 100px;">
								<div onclick="javascript:addTask()">新增任务</div>
								<div onclick="javascript:deleteTask()">删除任务</div>
								<div onclick="javascript:updateTask()">修改任务</div>
								<div onclick="javascript:viewTask()">查看任务</div>
							</div>
						</th>
					</tr>
					<tr>
						<th>阶段名称</th>
						<th>任务名称</th>
						<th>任务名称</th>
						<th>任务名称</th>
						<th>任务名称</th>
						<th>任务名称</th>
						<th>任务名称</th>
						<th>任务名称</th>
					</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
		</form>
	</div>
</body>
</html>
